package com.bitdf.txing.users.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.bitdf.txing.common.utils.R;
import com.bitdf.txing.users.entity.UserReceiveAddressEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;


/**
 * 会员收货地址
 *
 * @author lizhiwei
 * @email sunlightcs@gmail.com
 * @date 2022-05-16 22:21:48
 */
@RestController
@RequestMapping("${txing.request.path.users}/address")
public class UserReceiveAddressController {
    @Autowired
    private com.bitdf.txing.users.service.UserReceiveAddressService userReceiveAddressService;

    /**
     * 根据user_id获取收获地址
     * @param userId
     * @return
     */
    @GetMapping("/get/{memberId}")
    @SaCheckLogin
    public List<UserReceiveAddressEntity> getAddress(@PathVariable("memberId") Long userId){
        return userReceiveAddressService.getAddress(userId);
    }

    /**
     * 列表
     */
//    @RequestMapping("/list")
//    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = UserReceiveAddressService.queryPage(params);
//
//        return R.ok().put("page", page);
//    }


    /**
     * 信息
     */
    @SaCheckLogin
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		UserReceiveAddressEntity UserReceiveAddress = userReceiveAddressService.getById(id);

        return R.ok().put("data", UserReceiveAddress);
    }

    /**
     * 保存
     */
    @SaCheckLogin
    @RequestMapping("/save")
    public R save(@RequestBody UserReceiveAddressEntity UserReceiveAddress){
		userReceiveAddressService.save(UserReceiveAddress);

        return R.ok();
    }

    /**
     * 修改
     */
    @SaCheckLogin
    @RequestMapping("/update")
    public R update(@RequestBody UserReceiveAddressEntity UserReceiveAddress){
		userReceiveAddressService.updateById(UserReceiveAddress);

        return R.ok();
    }

    /**
     * 删除
     */
    @SaCheckLogin
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		userReceiveAddressService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
